Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #4840: Alias class prototype for methods in loose mode #5560

Merged
merged 2 commits into from Aug 27, 2017

Conversation

oliverdon
Copy link
Contributor

Q A
Patch: Bug Fix? no
Major: Breaking Change? no
Minor: New Feature? no
Deprecations? no
Spec Compliancy? yes?
Tests Added/Pass? yes
Fixed Tickets Fixes #4840
License MIT
Doc PR no
Dependency Changes no

Alias class prototype for methods in loose mode.

@mention-bot
Copy link

@oliverdon, thanks for your PR! By analyzing the history of the files in this pull request, we identified @existentialism, @loganfsmyth and @hzoo to be potential reviewers.

@hzoo hzoo added the PR: Polish 💅 A type of pull request used for our changelog categories label Mar 28, 2017
if (!this.aliasInserted) {
const classProto = t.memberExpression(this.classRef, t.identifier("prototype"));
const protoDeclaration = t.variableDeclaration("var", [
t.variableDeclarator(t.identifier(this.methodAlias), classProto),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be a unique identifier, not the known I'd _proto.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, that makes sense.

would replacing line 10:

this.methodAlias = "_proto";

with

this.methodAlias = this.path.scope.generateUidIdentifier("proto").name;

be a good way of achieving this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made the change, and caught up changes from 7.0.

@oliverdon oliverdon force-pushed the loose-class-reuse-prototype branch from 57f02e7 to 56fd0c6 Compare July 21, 2017 19:42
t.identifier("prototype"),
);
const protoDeclaration = t.variableDeclaration("var", [
t.variableDeclarator(t.identifier(this.methodAlias), classProto),
Copy link
Member

@hzoo hzoo Jul 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are going to use generateUidIdentifier, then you should just the identifier part and not do the .name 😄

this.methodAlias = this.path.scope.generateUidIdentifier("proto")
t.variableDeclarator(this.methodAlias, classProto),

Copy link
Contributor Author

@oliverdon oliverdon Jul 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, good point 😅, done.

@oliverdon oliverdon force-pushed the loose-class-reuse-prototype branch from 56fd0c6 to 53268dc Compare July 21, 2017 20:12
@@ -6,6 +6,25 @@ export default class LooseClassTransformer extends VanillaTransformer {
constructor() {
super(...arguments);
this.isLoose = true;
this.aliasInserted = false;
this.methodAlias = this.path.scope.generateUidIdentifier("proto");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: this uses a global name. We can instead test if methodAlias is set yet, and create it when needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, removed this from constructor.

@oliverdon oliverdon force-pushed the loose-class-reuse-prototype branch 2 times, most recently from 1897e78 to ff11dce Compare July 21, 2017 20:46
@babel-bot
Copy link
Collaborator

babel-bot commented Aug 26, 2017

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/4709/

@jridgewell jridgewell merged commit 960151c into babel:7.0 Aug 27, 2017
@hzoo
Copy link
Member

hzoo commented Aug 27, 2017

@oliverdon thanks for your efforts! awesome stuff.

^ aside: btw we should figure out plugin options (loose mode) for the repl

@hzoo hzoo mentioned this pull request Sep 16, 2017
2 tasks
@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Oct 6, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: Polish 💅 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants